package cn.xzc.job.type;

import cn.xzc.job.Trigger;
import cn.xzc.job.pojo.Job;

import java.util.Objects;

/**
 * 执行任务+下次执行触发时间
 * 直接标明下次触发执行时间的任务类型
 *
 * @author xzc
 * 当前时间 2024-02-12 21:30:00
 */
public class TriggerJob extends Job {

    private final Trigger trigger;


    /**
     * Create a new {@link TriggerJob}.
     *
     * @param runnable the underlying task to execute
     * @param trigger  specifies when the task should be executed
     */
    public TriggerJob(Runnable runnable, Trigger trigger) {
        super(runnable);
        assert trigger != null : "Trigger must not be null";
        this.trigger = trigger;
    }


    /**
     * Return the associated trigger.
     */
    public Trigger getTrigger() {
        return this.trigger;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof TriggerJob)) {
            return false;
        }
        if (!super.equals(o)) {
            return false;
        }
        TriggerJob that = (TriggerJob) o;
        return Objects.equals(trigger, that.trigger);
    }

    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), trigger);
    }
}